from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

from app.api.v1.bookings import router as bookings_router
from app.api.v1.flights import router as flights_router
from app.api.v1.passengers import router as passengers_router
from app.api.v1.reports import router as reports_router
from app.config import Base
from app.config.database_config import PgManager

manager = PgManager()
# 创建数据库表
Base.metadata.create_all(bind=manager.engine)

app = FastAPI(
    title="航班管理系统",
    description="基于FastAPI的航班管理API",
    version="1.0.0"
)

# 配置CORS
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# 注册路由
app.include_router(flights_router)
app.include_router(passengers_router)
app.include_router(bookings_router)
app.include_router(reports_router)


@app.get("/")
def read_root():
    return {"message": "欢迎使用航班管理系统API", "version": "1.0.0"}


@app.get("/health")
def health_check():
    return {"status": "healthy", "service": "flight-system-api"}


if __name__ == "__main__":
    import uvicorn

    uvicorn.run(app, host="0.0.0.0", port=8000)
